package com.project.service;


import com.project.dao.ExerKpointMapper;
import com.project.entity.ExerKpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(rollbackFor = Exception.class)
@Service
public class ExerkpointServiceImpl implements ExerkpointService{

    @Autowired
    ExerKpointMapper exerKpointMapper;

    @Override
    public int add(ExerKpoint exerKpoint)
    {
        return exerKpointMapper.insertSelective(exerKpoint);
    }

    @Override
    public void addBatch(Integer exerinfoId,List<Integer> kpointList)
    {
        exerKpointMapper.deleteByExerinfoId(exerinfoId);
        for(Integer kpointId : kpointList)
        {
            ExerKpoint exerKpoint = new ExerKpoint();
            exerKpoint.setKpointid(kpointId);
            exerKpoint.setExerinfoid(exerinfoId);
            exerKpointMapper.insertSelective(exerKpoint);
        }
    }

    @Override
    public List<ExerKpoint> findByExerInfoId(Integer exerInfoId)
    {
        return exerKpointMapper.selectByExerInfoId(exerInfoId);
    }
}
